# -*- coding:utf-8 -*-
import django.utils.timezone as timezone
from django.db import models
from libs.base.basedb import Basemodel
from account.models import User

class Article(Basemodel):
    details = models.TextField(null=True,verbose_name='详情')
    abstract = models.CharField(null=True, max_length=150,verbose_name='摘要')
    user = models.ForeignKey(User, null=True,verbose_name='发表用户',related_name='articles_user')
    file = models.FileField(upload_to='attachment/', null=True)
    plate = models.ForeignKey('Plate',null=True,verbose_name='板块',related_name='articles_plate')
    label = models.ManyToManyField('Label', null=True, verbose_name='标签', related_name='articles_label')
    visit_number = models.IntegerField(default=0,verbose_name='游览次数')
    thumb_number = models.IntegerField(default=0)

    class Meta:
        verbose_name = "文章"
        verbose_name_plural = verbose_name



class CommentFrist(Basemodel):
    article = models.ForeignKey('Article',null=True,related_name='comments',verbose_name='评论的文章')
    user = models.ForeignKey(User, null=True, verbose_name='发表用户', related_name='comments_frist')
    thumb_number = models.IntegerField(default=0)

    class Meta:
        verbose_name = "一级评论"
        verbose_name_plural = verbose_name



class CommentSecondary(Basemodel):
    commentFrist = models.ForeignKey('CommentFrist',null=True,related_name='comments_secondary',verbose_name='commentsecondarys')
    user = models.ForeignKey(User, null=True, verbose_name='发表用户', related_name='commentsecondarys_user')
    thumb_number = models.IntegerField(default=0)

    class Meta:
        verbose_name = "二级评论"
        verbose_name_plural = verbose_name



class Plate(models.Model):
    name = models.CharField(null=True, max_length=5, verbose_name='板块名')
    moderator = models.ForeignKey(User, null=True, verbose_name='版主', related_name='moderator')
    management_one = models.ManyToManyField(User, null=True, verbose_name='管理员', related_name='management_one')
    management_two = models.ManyToManyField(User, null=True, verbose_name='管理员', related_name='management_two')
    management_three = models.ManyToManyField(User, null=True, verbose_name='管理员', related_name='management_three')
    class Meta:
        verbose_name = "板块"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class Label(models.Model):
    name = models.CharField(null=True, max_length=5,verbose_name='标签名')
    class Meta:
        verbose_name = "标签"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name







